# -*- coding: utf-8 -*-
"""
Created on Mon Oct 23 10:25:05 2023

@author: HD
"""

import random
import sys
import time

import pandas as pd
from pandas import DataFrame


def mock_data() -> DataFrame:
    # 定义变量数量和观测值数量
    # num_variables = 10000
    num_variables = 100
    # num_observations = 30
    num_observations = 3

    def get_variable_size(variable):
        size_bytes = sys.getsizeof(variable)
        size_kb = size_bytes / 1024
        return size_kb

    # 生成随机时间序列数据
    data = {f"Variable_{i + 1}": [random.uniform(0, 10) for _ in range(num_observations)] for i in range(num_variables)}

    # 将时间序列数yh据转换为DataFrame
    df = pd.DataFrame(data)
    print(f'data: {df}')
    return df


def solve(df: DataFrame):
    # 这个玩意 需要CUDA
    from cuml.tsa.auto_arima import AutoARIMA

    # print("Size of df:", get_variable_size(df), "KB")

    # 打印DataFrame
    print(df)
    start_time = time.time()
    model = AutoARIMA(df)
    model.search(s=7, d=(0, 1), D=(0, 1), p=(0, 2, 4), q=(0, 2, 4), P=range(2), Q=range(2), method="css", truncate=20)
    model.fit(method="css-ml")
    fc = model.forecast(3)

    end_time = time.time()
    # 计算代码块的运行时间
    execution_time = end_time - start_time
    print(fc)
    print("代码块的运行时间为:", execution_time, "秒")

    '''
    start_time = time.time()
    model = ARIMA(df, order=(1,1,1), seasonal_order=(1,1,1,7),
                  fit_intercept=False)
    model.fit()
    forecast_df = model.forecast(3)
    end_time = time.time()
    execution_time = end_time - start_time
    print("代码块的运行时间为:", execution_time, "秒")
    print(forecast_df)

    # forecast_df.columns = df.columns
    # forecast_df.to_csv("forecasts.csv", index=False)

    '''


def main():
    data = mock_data()
    solve(data)


if __name__ == '__main__':
    main()
